home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C20 / PriorityQueue2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  701 b   |  32 lines

  1. //: C20:PriorityQueue2.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Changing the priority
  7. #include <iostream>
  8. #include <queue>
  9. #include <cstdlib>
  10. #include <ctime>
  11. using namespace std;
  12.  
  13. struct Reverse {
  14.   bool operator()(int x, int y) {
  15.     return y < x;
  16.   }
  17. };
  18.  
  19. int main() {
  20.   priority_queue<int, vector<int>, Reverse> pqi;
  21.   // Could also say:
  22.   // priority_queue<int, vector<int>, 
  23.   //   greater<int> > pqi;
  24.   srand(time(0));
  25.   for(int i = 0; i < 100; i++)
  26.     pqi.push(rand() % 25);
  27.   while(!pqi.empty()) {
  28.     cout << pqi.top() << ' ';
  29.     pqi.pop();
  30.   }
  31. } ///:~
  32.